<template>
  <div class="notfound">
    <svg-icon name="404" />
    <div class="content">
      <h1>404</h1>
      <div class="desc">抱歉，你访问的页面不存在</div>
      <t-button class="pb-[7px] pt-[7px] text-[14px]" type="primary" @click="goBack"
        >{{ countdown }}秒后，返回首页</t-button
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "NotFound",
  beforeRouteLeave(to, from, next) {
    clearInterval(this.inter);
    next();
  },
  data() {
    return {
      inter: null,
      countdown: 5,
    };
  },
  mounted() {
    if (this.$store.state.settings.enableTabbar) {
      this.$store.dispatch("tabbar/remove", this.$route.meta.activeMenu || this.$route.fullPath);
    }
    this.inter = setInterval(() => {
      this.countdown--;
      if (this.countdown == 0) {
        clearInterval(this.inter);
        this.goBack();
      }
    }, 1000);
  },
  methods: {
    goBack() {
      this.$router.push("/");
    },
  },
};
</script>

<style lang="scss" scoped>
.notfound {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 700px;

  @include position-center(xy);

  .svg-icon {
    width: 400px;
    height: 400px;
  }

  .content {
    h1 {
      margin: 0;
      font-size: 72px;
      color: #363f51;
    }

    .desc {
      margin: 20px 0 30px;
      font-size: 20px;
      color: #515a6e;
    }
  }
}
</style>
